#pragma once
#include "Fysics/Dependencies.h"
#include "Fysics/Event/EventDispatcher.h"
#include "Space/Space.h"

namespace Fysics
{
	class VirtualMachine;

	enum class ApplicationState
	{
		CREATE,
		START,
		RESTART,
		UPDATE,
		STOP,
		DESTROY
	};

	class Application
	{
	private:
		std::string m_Name;
		EventDispatcher m_EventDispatcher;
		ApplicationState m_RunningState;
	protected:
		std::vector<Space*> m_SpaceList;
		Space* m_CurrentSpace;

		VirtualMachine& System();

		void RegisterSpace(Space* space, bool isStartup);
	public:
		int LifeTime;

		Application(const char* appName, const char* iconFilePath);
		virtual ~Application();

		virtual void OnStart() {}
		virtual void OnRestart() {}
		virtual void OnUpdate() {}
		virtual void OnStop() {}
		virtual void Render();
		virtual void ScreenRender();

		virtual void RegisterAllSpaces() = 0;

		void Run();
		void OnEvent(Event& event);
		void SwitchSpace(const std::string& spacename);
	};
}